
var ATM = function() {
  this.cnt = new Array(5).fill(0)
  this.val = [20, 50, 100, 200, 500]
};

/** 
 * @param {number[]} banknotesCount
 * @return {void}
 */
ATM.prototype.deposit = function(banknotesCount) {
  const { cnt } = this
  for(let i = 0; i<banknotesCount.length; i++) {
    cnt[i] += banknotesCount[i]
  }
};

/** 
 * @param {number} amount
 * @return {number[]}
 */
ATM.prototype.withdraw = function(amount) {
  const { cnt, val } = this
  const c = new Array(5).fill(0)
  for(let i = 4; i>=0; i--) {
    if(amount >= val[i] && cnt[i]) {
      if(val[i] * cnt[i] <= amount) {
        c[i] = cnt[i]
        amount -= val[i] * cnt[i]
        continue
      }
      let x = Math.floor(amount/val[i])
      amount -= x * val[i]
      c[i] = x
    }
  }
  if(amount) return [-1]
  for(let i = 0; i<5; i++) {
    cnt[i] -= c[i]
  }
  return c
};

/**
 * Your ATM object will be instantiated and called as such:
 * var obj = new ATM()
 * obj.deposit(banknotesCount)
 * var param_2 = obj.withdraw(amount)
 */